import util from "@/libs/util";

export default ({ request }) => ({
  /**
   * @description 加入购物车
   * @param {Object} data
   */
  ADD_TO_CAR(data = {}) {
    let userinfo = util.store.getItem("userinfo");
    data.user_id = userinfo ? userinfo.user_id : null;

    return request({
      url: "/data/v1/addToCart",
      method: "post",
      data: data,
    });
  },
  /**
   * @description 购物车列表
   * @param {Object} data
   */
  MY_CAR() {
    let userinfo = util.store.getItem("userinfo");
    if (!userinfo) return;
    return request({
      url: "/data/v1/myCart",
      method: "post",
      data: { user_id: userinfo.user_id },
    });
  },
  /**
   * @description 购物车商品加减数量
   * @param {Object} data
   */
  CAR_ADD_DESC(data = {}) {
    let userinfo = util.store.getItem("userinfo");
    data.user_id = userinfo.user_id;
    return request({
      url: "/data/v1/cartAddDesc",
      method: "post",
      data: data,
    });
  },
  /**
   * @description 购物车商品删除
   * @param {Object} data
   */
  CAR_DEL(cart_id) {
    return request({
      url: "/data/v1/cartDelete",
      method: "post",
      data: { cart_id: [cart_id] },
    });
  },
  /**
   * @description 获取购物车商品的优惠券
   * @param {*} data
   */
  GET_COUPON(data) {
    return request({
      url: "/data/v1/cartCoupon",
      method: "post",
      data: data,
    });
  },
});
